import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/pages/Home'
import Search from '@/pages/Search'
import Register from '@/pages/Register'
import Login from '@/pages/Login'
// var originPush = VueRouter.prototype.push
// 重写push()方法

// VueRouter.prototype.push = function (location, resolve, reject) {
//   console.log(this)
//   if (resolve && reject) {
//     originPush.call(this, location, resolve, reject)
//   } else {
//     originPush.call(this, location, () => {}, () => {})
//   }
// }
// console.log(VueRouter)
Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/login',
      component: Login,
      meta: {
        show: false
      }
    },
    {
      path: '/home',
      component: Home,
      meta: {
        show: true
      },
      name: 'home'
    },
    {
      path: '/search/:keyword?',
      component: Search,
      meta: {
        show: true
      },
      name: 'search',
      props: true

    },
    {
      path: '/register',
      component: Register,
      meta: {
        show: false
      }
    }
  ]
})

export default router
